home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libcommon / scale.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.9 KB  |  83 lines

  1. /*
  2.  * scale.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  * 
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * scale.c,v 4.1 1994/08/09 07:55:11 explorer Exp
  17.  *
  18.  * scale.c,v
  19.  * Revision 4.1  1994/08/09  07:55:11  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:02  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:32:08  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "common.h"
  30. #include "scale.h"
  31.  
  32. TransMethods *iScaleMethods;
  33. void ScaleMatrix();
  34.  
  35. Scale *
  36. ScaleCreate()
  37. {
  38.     Scale *res;
  39.  
  40.     res = (Scale *)Malloc(sizeof(Scale));
  41.     res->x = res->y = res->z = 1.;
  42.     return res;
  43. }
  44.  
  45. TransMethods *
  46. ScaleMethods()
  47. {
  48.     if (iScaleMethods == (TransMethods *)NULL) {
  49.         iScaleMethods = (TransMethods *)Malloc(sizeof(TransMethods));
  50.         iScaleMethods->create = (TransCreateFunc *)ScaleCreate;
  51.         iScaleMethods->propagate = ScalePropagate;
  52.     }
  53.     return iScaleMethods;    
  54. }
  55.  
  56. void
  57. ScalePropagate(scale, trans, itrans)
  58. Scale *scale;
  59. RSMatrix *trans, *itrans;
  60. {
  61.     if (equal(scale->x, 0.) || equal(scale->y, 0.) || equal(scale->z, 0.))
  62.         RLerror(RL_PANIC, "Degenerate scale %g %g %g\n", scale->x, scale->y, scale->z);
  63.     ScaleMatrix(scale->x, scale->y, scale->z, trans);
  64.     /*
  65.      * Build the inverse
  66.      */
  67.     MatrixInit(itrans);
  68.     itrans->matrix[0][0] = 1. / scale->x;
  69.     itrans->matrix[1][1] = 1. / scale->y;
  70.     itrans->matrix[2][2] = 1. / scale->z;
  71. }
  72.  
  73. void
  74. ScaleMatrix(x, y, z, mat)
  75. Float x, y, z;
  76. RSMatrix *mat;
  77. {
  78.     MatrixInit(mat);
  79.     mat->matrix[0][0] = x;
  80.     mat->matrix[1][1] = y;
  81.     mat->matrix[2][2] = z;
  82. }
  83.